#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

typedef struct
{
    char name[4];
    int age;
} Student;

int main()
{
    int fd = open("stu.dat", O_RDONLY);
    if (fd == -1)
    {
        perror("open");
        return 1;
    }

    Student *p = mmap(NULL, 10 * sizeof(Student), PROT_READ, MAP_SHARED, fd, 0);
    if (p == MAP_FAILED)
    {
        perror("mmap");
        close(fd);
        return 1;
    }

    printf("Name: %s Age: %d\n", p[0].name, p[0].age);

    if (munmap(p, 10 * sizeof(Student)) == -1)
    {
        perror("munmap");
    }

    close(fd);
    return 0;
}